package 韩顺平集合.List;

import java.util.ArrayList;
import java.util.Iterator;

public class p9list遍历的三种方式 {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add("张三");
        list.add("李四");
        list.add("王麻子");
        System.out.println("第一种遍历方式");
        Iterator iterator = list.iterator();
        while(iterator.hasNext()){
            Object next = iterator.next();
            System.out.println(next);
        }
        System.out.println("第二种遍历方式");
        for (Object e: list){
            System.out.println(e);
        }
        System.out.println("第三种遍历方式,当作一个数组");
        for (int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }

    }
}
